<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>蜗牛图书商城</title>
</head>
<body>
	<!-- 标题栏 -->
	<jsp:include page="header.jsp"></jsp:include>

	<!-- 商品展示 -->
	<div class="col-md-10 col-md-push-1">

		<div class="col-md-12 bg-danger text-left"
			style="margin-bottom: 10px">
			<div class="col-md-6 text-left">
				<h3>搜索结果(为您找到相关商品${pageBean.totalNum}个)</h3>
			</div>
			<div class="col-md-6 text-right">
				<a class="btn btn-lg btn-primary" href="index.jsp"
					style="height: 56px;padding-top:15px">返回首页</a>
			</div>
		</div>
		<div style="height: 630px;">
			<div class="col-md-12 bg-warning text-center" id="list">
				<c:forEach items="${list}" var="goods" varStatus="status">
					<div class="col-md-12 bg-danger"
						style="margin-top: 5px; margin-bottom: 5px">
						<!-- 商品图片 -->
						<div class="col-md-2 bg-info text-center"
							onclick="goodsInfo(${goods.gid})">
							<img height="120px" src="${goods.gpic}">
						</div>
						<!-- 商品信息 -->
						<div class="col-md-10  text-left">
							<div class="col-md-6 bg-danger" style="height: 40px;"
								onclick="goodsInfo(${goods.gid})">
								<h4>${goods.gname}</h4>
							</div>
							<div class="col-md-6 bg-danger" style="height: 40px; padding: 0">
								<div class="col-md-3 bg-info" style="height: 40px;">
									<h4>
										<strong>${goods.gtname}</strong>
									</h4>
								</div>
								<div class="col-md-3 bg-primary" style="height: 40px;">
									<h4>￥${goods.gprice}</h4>
								</div>
								<div class="col-md-6 bg-info text-right">
									<button class="btn btn-sm btn-info" style="height: 40px;"
										onclick="addCart(${goods.gid})">加入购物车</button>
									<button class="btn btn-sm btn-success" style="height: 40px;"
										onclick="buy(${goods.gid})">立即购买</button>
								</div>
							</div>
							<div class="col-md-12 bg-warning"
								onclick="goodsInfo(${goods.gid})"
								style="height: 80px; overflow: hidden">
								<label>${goods.gdesc}</label>
							</div>
						</div>
					</div>
				</c:forEach>
				<div class="col-md-12 bg-success text-center" id="pageNav">
					<button class="btn btn-xs btn-primary" onclick="goPage(1)">首页</button>
					<button class="btn btn-xs btn-primary"
						onclick="goPage(${pageBean.page==1?1:pageBean.page-1})">上一页</button>
					<button class="btn btn-xs btn-primary"
						onclick="goPage(${pageBean.page==pageBean.totalPage?pageBean.totalPage:pageBean.page+1})">下一页</button>
					<button class="btn btn-xs btn-primary"
						onclick="goPage(${pageBean.totalPage})">末页</button>
					<br> <span>共${pageBean.totalPage}页，现在是第${pageBean.page}页。</span>
				</div>
				<div class='col-md-12 bg-warning' style="height: 50px;"></div>
			</div>
		</div>
	</div>
	<!-- 版权页 -->
	<jsp:include page="footer.jsp"></jsp:include>
</body>
<script type="text/javascript">
	let nowPage=${pageBean.page};

	function goodsInfo(gid) {
		location.href="goods?opr=initGoodsInfo&gid="+gid;
	}
	
	function goPage(page){
		if (page!=nowPage) {
			nowPage=page;
			location.href="goods?opr=search&wd=${wd}&page="+page;
		}
	}
</script>
</html>